/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProcessoPesquisaGUI.java
 *
 * Created on 01/03/2010, 18:24:26
 */

package gui;

import facade.AdvogadoFacade;
import java.awt.Component;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import modelo.Processo;

/**
 *
 * @author andrehadm
 */
public class ProcessoPesquisaGUI extends javax.swing.JPanel {

    private AdvogadoFacade advogadoFacade;
    private JPanel areaDeTrabalho;
    private JToolBar barraDeFerramentas;

    /** Creates new form ProcessoPesquisaGUI */
    public ProcessoPesquisaGUI(JPanel areaDeTrabalho, JToolBar barra, AdvogadoFacade advogadoFacade) {
        this.advogadoFacade = advogadoFacade;
        this.areaDeTrabalho = areaDeTrabalho;
        this.barraDeFerramentas = barra;
        initComponents();
        carregaProcesso();
    }

    private void habilitaBotoesBarraDeFerramentas(){
        for (Component botoes: barraDeFerramentas.getComponents()) {
            botoes.setEnabled(true);
        }
        System.out.println("");
        System.out.println("Todos os botoes habilitados.");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox_Processo = new javax.swing.JComboBox();
        jButton_Sair = new javax.swing.JButton();
        jButton_Carregar = new javax.swing.JButton();
        jPanelArea = new javax.swing.JPanel();

        setBorder(javax.swing.BorderFactory.createTitledBorder("Pesquisas Processo"));

        jButton_Sair.setText("Sair");
        jButton_Sair.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_SairMouseClicked(evt);
            }
        });

        jButton_Carregar.setText("Carregar");
        jButton_Carregar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_CarregarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelAreaLayout = new javax.swing.GroupLayout(jPanelArea);
        jPanelArea.setLayout(jPanelAreaLayout);
        jPanelAreaLayout.setHorizontalGroup(
            jPanelAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 536, Short.MAX_VALUE)
        );
        jPanelAreaLayout.setVerticalGroup(
            jPanelAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 330, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBox_Processo, 0, 403, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_Carregar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_Sair)
                .addContainerGap())
            .addComponent(jPanelArea, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox_Processo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton_Sair)
                    .addComponent(jButton_Carregar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelArea, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_SairMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_SairMouseClicked
        habilitaBotoesBarraDeFerramentas();
        areaDeTrabalho.removeAll();
        areaDeTrabalho.revalidate();
        areaDeTrabalho.repaint();
    }//GEN-LAST:event_jButton_SairMouseClicked

    private void jButton_CarregarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_CarregarMouseClicked
        ProcessoResultadoPesquisaGUI processoResultadoPesquisaGUI = new ProcessoResultadoPesquisaGUI( (Processo) jComboBox_Processo.getSelectedItem(), advogadoFacade);
        processoResultadoPesquisaGUI.setSize(jPanelArea.getWidth() - 15, jPanelArea.getHeight() - 15 );
        jPanelArea.removeAll();
        jPanelArea.add(processoResultadoPesquisaGUI);
        jPanelArea.revalidate();
        System.out.println(barraDeFerramentas.getComponentCount());
        //desabilitaBotoesBarraDeFerramentas();
        System.out.println("Processo Pesquisa.");
    }//GEN-LAST:event_jButton_CarregarMouseClicked

    private void carregaProcesso () {
        jComboBox_Processo.removeAllItems();
        System.out.println("");
        System.out.println("Carregando clientes");
        for (Processo processo : advogadoFacade.getTodosProcessos()) {
            jComboBox_Processo.addItem(processo);
            System.out.println("Processo: "+ processo.getId() + " - " + processo.getNome());
        }
        System.out.println("Tamanho da lista de processos: " + jComboBox_Processo.getItemCount());
        System.out.println("Processos carregados.");
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_Carregar;
    private javax.swing.JButton jButton_Sair;
    private javax.swing.JComboBox jComboBox_Processo;
    private javax.swing.JPanel jPanelArea;
    // End of variables declaration//GEN-END:variables

}
